#ifndef __SIPCLN_TRANSACTION_HPP__
#define __SIPCLN_TRANSACTION_HPP__

#include "resip/stack/SipMessage.hxx"
#include "resip/stack/ApplicationMessage.hxx"
#include "SipResipConfigure.hpp"

using namespace resip;

namespace wtsip{

class CSipClnTransaction;
class CSipUserAgent;
class CSipDialogBase;
    
class RESIP_PUBLIC CSipClnTransactionCallback{
public:

    //virtual bool onRequest(CSipClnTransaction& clntran, SipMessage& msg) = 0;
    virtual bool onDestroy(CSipClnTransaction& clntran) = 0;

    virtual bool onResponse(CSipClnTransaction& clntran, SipMessage& msg) = 0;
};


class RESIP_PUBLIC CSipClnTransaction{
protected:
    typedef enum
    {
        ClnInitial = 0,
        ClnProvisional,
        ClnCompleted,
        ClnFailed
    } ClnTranState;

public:
    CSipClnTransaction(SipMessage& request, CSipUserAgent& ua);

    virtual ~CSipClnTransaction();

    virtual bool processIncoming(SipMessage* msg);

    virtual bool processTimeOut(ApplicationMessage* msg);

    virtual bool send(std::auto_ptr<SipMessage> msg);

    bool registerCallback(CSipClnTransactionCallback* callback);

    bool unregisterCallback();

    bool bindDialog(CSipDialogBase* dialog);

    SipMessage& getRequest();

    resip::Data& getTid();

    CSipDialogBase* getBindDlg();

    bool hasCallback(){ return (m_callback != NULL); }

protected:
    virtual bool setState(int state);

protected:
    int m_State;

    CSipUserAgent& m_ua;

    SipMessage m_request;

    CSipDialogBase* m_bindDialog;

    resip::Data m_tid;

    MethodTypes m_mth;

    CSipClnTransactionCallback* m_callback;
};


}//namespace

#endif

